package com.db.commute;

import java.util.*;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class CommuteDAO{
	private SqlMapClientTemplate template;
	// Spring 으로부터 설정된 SqlMapClientTemplate 객체를 받는다
	public void setTemplate(SqlMapClientTemplate template) {
		this.template = template;
	}	

	public boolean IsExist(int sabun){
		boolean check = false;
		try {
			int count = (Integer) template.queryForObject("commIsExist", sabun);
			if(count == 0){
				check = false;
			}else{
				check = true;
			}
		} catch (Exception e) {
			System.out.println("CommuteDAO.IsExist():"+e.toString());
		}
		return check;
	}
	
	public void Insert(int sabun){
		try {
			template.insert("commInsert", sabun);
		} catch (Exception e) {
			System.out.println("CommuteDAO.Insert():"+e.toString());
		}		
	}
	
	public int getCno(int sabun){
		int cno = 0;
		try {
			cno = (Integer) template.queryForObject("commGetCno", sabun);
		} catch (Exception e) {
			System.out.println("CommuteDAO.getCno():"+e.toString());
		}
		return cno;
	}
	
	public boolean CwExist(int cno){
		boolean check = false;
		try {
			int count = (Integer)template.queryForObject("commCwExist", cno);			
			if(count == 0){
				check = false;
			}else{
				check = true;
			}
		} catch (Exception e) {
			System.out.println("CommuteDAO.CwExist():"+e.toString());			
		}		
		System.out.println(check);
		return check;
	}

	public boolean LwExist(int cno){
		boolean check = false;
		try {
			int count = (Integer)template.queryForObject("commLwExist", cno);			
			if(count == 0){
				check = false;
			}else{
				check = true;
			}
		} catch (Exception e) {
			System.out.println("CommuteDAO.LwExist():"+e.toString());
		}
		System.out.println(check);
		return check;		
	}
	
	public void UpdateCwork(int cno){
		try {
			template.update("commUpdateCwork", cno);
		} catch (Exception e) {
			System.out.println("CommuteDAO.UpdateCwork():"+e.toString());
		}		
	}
	
	public void UpdateLwork(int cno){
		try {
			template.update("commUpdateLwork", cno);
		} catch (Exception e) {
			System.out.println("CommuteDAO.UpdateLwork():"+e.toString());
		}		
	}
	
	public List<Object> getListDay(CommuteVO vo){
		List<Object> list = new ArrayList<Object>();
		try {
			list = template.queryForList("commListDay", vo);
		} catch (Exception e) {
			System.out.println("CommuteDAO.getListDay():"+e.toString());
		}
		return list;
	}
	
	public List<CommuteVO> getListMonth(CommuteVO vo){
		List<CommuteVO> list = new ArrayList<CommuteVO>();
		try {			
			list = template.queryForList("commListMonth", vo);
		} catch (Exception e) {
			System.out.println("CommuteDAO.getListMonth():"+e.toString());
		}
		return list;
	}
	
	public List<CommuteVO> getListWeek(CommuteVO vo){
		List<CommuteVO> list = new ArrayList<CommuteVO>();
		try {
			list = template.queryForList("commListWeek", vo);
		} catch (Exception e) {
			System.out.println("CommuteDAO.getListWeek():"+e.toString());
		}
		return list;
	}
	
	public List<Integer> getSabunList(){
		List<Integer> list = new ArrayList<Integer>();
		try {
			list = template.queryForList("getSabunList");
		} catch (Exception e) {
			System.out.println("CommuteDAO.getSabunList():"+e.toString());
		}
		return list;
	}
}
